package com.jinmdz.fmis.generator.dao;

import com.jinmdz.fmis.generator.model.ColumnInfo;
import com.jinmdz.fmis.generator.model.TableInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

/**
 * @author LiCongLu
 * @date 2019-12-13 14:16
 */
public interface MetadataDao {

    /**
     * 获取数据库表列表
     *
     * @param
     * @return ArrayList<TableInfo>
     * @author LiCongLu
     * @date 2019-12-16 13:07
     */
    @Select(" select TABLE_SCHEMA,TABLE_NAME,TABLE_COMMENT from information_schema.TABLES where TABLE_SCHEMA = (select database())")
    ArrayList<TableInfo> listTableInfo();

    /**
     * 获取数据库表信息
     *
     * @param tableName 表名
     * @return TableInfo
     * @author LiCongLu
     * @date 2019-12-17 14:28
     */
    @Select(" select TABLE_SCHEMA,TABLE_NAME,TABLE_COMMENT from information_schema.TABLES where TABLE_SCHEMA = (select database()) and TABLE_NAME=#{tableName}")
    TableInfo getTableInfo(@Param("tableName") String tableName);

    /**
     * 获取数据表结构
     *
     * @param tableName 表名称
     * @return ArrayList<ColumnInfo>
     * @author LiCongLu
     * @date 2019-12-16 13:07
     */
    @Select(" select TABLE_NAME,COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,ORDINAL_POSITION,COLUMN_COMMENT from information_schema.COLUMNS where TABLE_SCHEMA = (select database()) and TABLE_NAME=#{tableName}")
    ArrayList<ColumnInfo> listColumnInfo(@Param("tableName") String tableName);
}
